package com.woniuxy.microsysserver.configure;


import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * WebSocket的配置类
 * @EnableWebSocketMessageBroker 开启后端的WebSocket支持
 */
@EnableWebSocketMessageBroker
@Configuration
public class WebSocketConfiguration implements WebSocketMessageBrokerConfigurer {
    /**
     * 配置连接位置
     * 相当于：ServerSocket ss = new ServerSocket(9999);
     * @param registry
     */
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/endpointWisely").setAllowedOrigins("*");
    }

    /**
     * 配置消息的注册方式
     * @param registry
     */
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        //topic 消息主题模式（发布/订阅模式   广播模式）
        //queue 队列模式（点对点模式）
        registry.enableSimpleBroker("/topic");
    }
}
